package com.peaker.advertisingpro.db.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.peaker.advertisingpro.bean.ProgramUrlBean
import com.peaker.advertisingpro.bean.ResPlayNum

/**
 * 资源播放次数统计
 */
@Dao
interface ResPlayNumDao :BaseDao<ResPlayNum> {

    /**
     * 获取节目播放次数
     * @param id String
     * @return MutableList<ProgramUrlBean>
     */
    @Query("SELECT number FROM resplaydb WHERE countId = :id")
    fun getPlayCount(id: String): Int?

    /**
     * 清空播放次数
     */
    @Query("UPDATE resplaydb SET number = 0")
    fun clearPlayCount()

    /**
     * 播放次数加一
     * @param id String
     */
    @Query("UPDATE resplaydb SET number = number+1 WHERE countId = :id")
    fun addPlayCount(id: String)

    /**
     * 获取所有
     * @return MutableList<ResPlayNum>
     */
    @Query("SELECT * FROM resplaydb")
    fun getProgramUrlBean(): MutableList<ResPlayNum>

    @Query("DELETE FROM resplaydb")
    fun deletAll()

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(entitie: ResPlayNum?)


}